package 试题和试卷;

import GUI.*;
import 数据库和网络.myDatebase;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class questionBaseItem {
     public JLabel num,paperLabel;
    public JButton detailButton,doButton;
    public question currentquestion;

    public questionBaseItem(){}

    public questionBaseItem(int n,question currentquestion){
        this.currentquestion=currentquestion;
        num = new JLabel(""+n);
        int loc ;
        if(n%5!=0){
            loc=n%5;
        }else {
            loc=5;
        }
        setTitleType(num);
        paperLabel = new JLabel("试题名："+currentquestion.getTitle()+"  ");
        /*先暂且只写了试卷名*/
        setTextType(paperLabel);
        num.setBounds(80,120+50*loc,60,50);
        paperLabel.setBounds(140,120+50*loc,600,50);
        detailButton = new JButton("详情与修改");
        doButton = new JButton("删除");
        setButtonType(detailButton);
        setButtonType(doButton);
        detailButton.setBounds(740,120+50*loc,80,50);
        doButton.setBounds(820,120+50*loc,80,50);


        myDatebase query=new myDatebase("questioncollection");
        String sql=String.format("select * from questioncollection.%s_question where questioncollection.%s_question.questionTitle='%s'",
                currentquestion.getType(),currentquestion.getType(),currentquestion.title);
        try {
            query.statement.execute(sql);
            query.resultSet=query.statement.executeQuery(sql);
            while(query.resultSet.next()){
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            query.close();
        }
    }

    public void setTitleType(JLabel label){
        Font bigFont = new Font("sanserif",Font.PLAIN,16);
        label.setBackground(Color.lightGray);
        label.setFont(bigFont);
        label.setOpaque(true);
        label.setBorder(BorderFactory.createLineBorder(Color.darkGray));
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }
    public void setTextType(JLabel label){
        Font smallFont = new Font("sanserif",Font.PLAIN,12);
        label.setBackground(Color.white);
        label.setOpaque(true);
        label.setFont(smallFont);
        label.setBorder(BorderFactory.createLineBorder(Color.lightGray));
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }
    public void setButtonType(JButton button){
        Font smallFont = new Font("sanserif",Font.PLAIN,14);
        //button.setBackground(Color.GRAY);
        button.setFont(smallFont);
        button.setBorder(BorderFactory.createLineBorder(Color.darkGray));
        button.setHorizontalAlignment(SwingConstants.CENTER);
    }

    public void add(){
    }

    public class detailListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            //加入查看试题详情
        }
    }

    public class startListener implements  ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            //根据题型不同赋值题目给出不同入口
        }
    }
}
